<template>
  <van-icon
    :color="value?'orange':'#777'"
    :name="value?'star':'star-o'"
    @click="onCollect"/>
</template>

<script>
import { addCollectArticle, deleteCollectArticle } from '@/api/article'
export default {
  name: 'CollectArticle',
  props: {
    value: {
      type: Boolean,
      required: true
    },
    articleId: {
      type: [Number, String, Object],
      required: true
    }
  },
  components: {},
  data () {
    return {

    }
  },
  created () {

  },
  methods: {
    async onCollect () {
      if (this.value) {
        // 取消
        await deleteCollectArticle(this.articleId)
      } else {
        // 新增
        await addCollectArticle(this.articleId)
      }
      this.$emit('input', !this.value)
    }
  }
}
</script>

<style lang="less" scoped>

</style>
